
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author sherin
 */
public class GUI {
    private Form messageForm;
    private TextField messageTxField;
    private TextBox messageTxBox;
    private static Command newMessageCommand = new Command("newMessage", Command.OK, 4);
    private Form loginDetails;
    private TextField ip;
    private TextField port;
    private Form userDetails;
    private TextField userName;
    private TextField password;
    private TextField cacheSize;
    private TextField VMName;
    private TextField VMRam;
    private TextField VMCores;
    private TextField VMHdd;
    private TextField VMOs;
    private Form VMForm;

    Form CreateVM(){
        VMForm = new Form( "vmFeatures");
        VMName = new TextField( "VMname", "", 10 , 0);
        VMRam = new TextField( "VMRam", "", 10, 0);
        VMCores = new TextField( "VMCores", "", 10, 0);
        VMHdd = new TextField( "VMHdd", "", 10, 0);
        VMOs = new TextField( "VMOs", "", 10, 0);


        List VMList = new List( "VMOS", Choice.POPUP);

        VMForm.append(VMName);
        VMForm.append(VMRam);
        VMForm.append(VMCores);
        VMForm.append(VMHdd);
        VMForm.append(VMOs);
     //   VMForm.append(VMList);
        VMForm.addCommand( lib.okCommand);
        return VMForm;

    }

    String VMCreate() {
        String message = "VM\nCreateVM\n"+VMName.getString() +"\n"+ VMRam.getString() +"\n"+ VMCores.getString()+"\n"+VMHdd.getString()+"\n"+VMOs.getString();
        System.out.println( message);
        return message;
    }

    String VMEdit() {
        String message = "VM\nEditVM\n"+ VMRam.getString()+"\n"+ VMCores.getString()+"\n"+VMHdd.getString()+"\n";
        System.out.println( message);
        return message;
    }

    Form editVMMenu(String VMName) {
        VMForm = new Form( "vmFeatures");
        VMRam = new TextField( "VMRam", "", 10, 0);
        VMCores = new TextField( "VMCores", "", 10, 0);


        VMHdd = new TextField( "VMHdd", "", 10, 0);
        VMForm.append(VMRam);
        VMForm.append(VMCores);
        VMForm.append(VMHdd);
        VMForm.addCommand( lib.okCommand);
        return VMForm;
    }

    List getServicesMenu1() {
        List VBServices = new List( "VBServices", Choice.IMPLICIT);
        VBServices.append("Create", null);
        VBServices.append("Start", null);
        VBServices.append("Edit", null);
        VBServices.append("Remove", null);
        VBServices.append("Stop", null);
      
        return VBServices;
    }



    Form getSettingsForm( RecordStore rs, int rId ) throws RecordStoreException{
     //   List connectMenu = new List("Settings List", Choice.IMPLICIT);


        byte bytes[];
        bytes = rs.getRecord(rId);

        
        if( bytes == null ){
            cacheSize = new TextField( "Cache Size", "1024", 50 , 0);
        }
        else{
            String value = bytes.toString();
            cacheSize = new TextField( "Cache Size", value, 50, 0);
        }

        //
/*

  */
        Form settings = new Form( "Settings" );
    //    
        settings.append(cacheSize);
        settings.addCommand(lib.backCommand);
        return settings;

    }

    public TextBox getMessageDisplayBox(String message) {
        messageTxBox = new TextBox("Message", message, 140, TextField.ANY);
        messageTxBox.addCommand(newMessageCommand);
        return messageTxBox;
    }

    public Form getServerLoginMenu() {
        System.out.println("getting login details");
        loginDetails = new Form("loginMenu");
        ip = new TextField("IP", "192.168.69.188", 50, 0); //TODO this entire stuff should display all the available connections, and
                                                            //for new connections the 'settings' link should be utilised
        //ip = new TextField("IP", "192.168.40.99", 50, 0);
        port = new TextField("Port", "8002", 50, 0 );
        Command connectCommand = new Command("Connect", Command.OK, 0);
        loginDetails.append(ip);
        loginDetails.append(port);
        loginDetails.addCommand(lib.backCommand);
        loginDetails.addCommand(connectCommand);
        return loginDetails;
    }

    public List getServicesMenu( String services[] ) {
        List servicesMenu = new List("Services Menu", Choice.IMPLICIT);
        //TODO  it should read from the mobile memory
        servicesMenu.append(services[1], null);
        servicesMenu.append("writeMessage", null); //TODO
        servicesMenu.addCommand(lib.exitCommand);
        servicesMenu.addCommand(lib.mainMenuCommand);
        return servicesMenu;
    }

    public List getMainMenu() {
        List menu = new List("Main Menu", Choice.IMPLICIT);
        Ticker ticker = new Ticker("George, Karthik, Sherin");
        menu.append("Connect", null);
        menu.append("Settings", null);
        menu.setTicker(ticker);
        menu.addCommand(lib.exitCommand);
        return menu;
    }




    Form getMessageForm() {
        messageForm = new Form("Message");
        messageTxField = new TextField("Message", "", 140, TextField.ANY);
        messageForm.append(messageTxField);
        messageForm.addCommand(lib.sendCommand);
        return messageForm;
    }

    String getMessageFromForm() {
        return messageTxField.getString();
    }
    
    String getIP() {
        return ip.getString();
    }

    String getPort() {
        return port.getString();
    }

    Form getUserDetailsMenu() {
        userDetails = new Form( "user");
        userName = new TextField( "Username", "", 140, TextField.ANY );
        password = new TextField( "Password", "", 140, TextField.PASSWORD);
        userDetails.append(userName);
        userDetails.append(password);
        userDetails.addCommand(lib.submit);
        return userDetails;
    }

    String getUsername(){
        return userName.getString();
    }

    String getPassword(){
        return password.getString();
    }

    List listVMs(String[] ResponseArray) {
        List VMs = new List( "Select Your VM", Choice.IMPLICIT );
        for( int i = 2; i < ResponseArray.length ; i++ ){
            VMs.append(ResponseArray[i], null);
        }
        VMs.addCommand(lib.okCommand );
        return VMs;

    }



 
}
